﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FFMpegConv
{
    /// <summary>
    /// 格式类型
    /// </summary>
    public enum BlueOptions
    {
        e480x320,
        e640x480,
        e800x600,
        e1024x768,
        e1280x720,
        e1920x1080,
        Ps3720p,
        ps31080p,
        TVStandardDef720x576pPALAVI,
        TVStandardDef720x576pPALMP4,
        TVHighDef1280x720pPALAVI,
        TVHighDef1280x720pPALMP4,
        TVHighDef1920x1080pPALAVI,
        TVHighDef1920x1080pPALMP4,
        TVHighDefPALMP4,


        MKV1,
        MKV2,
        SDflv,
        Lowqualflv,
        Mediumqualflv,
        Highqualflv,

        flv,


        Mp3_320kbs,
        Mp3_192kbs,
        Mp3_128kbs,
        LosslessCopy,

        /// <summary>
        /// 移动网络264Kbps视频编码
        /// </summary>
        M3U8_416X234_264Kbps,
        M3U8_480X270_464Kbps,
        M3U8_640X360_664Kbps,
        M3U8_640X360_1294Kbps,
        M3U8_960X540_3596Kbps,
        M3U8_1280X720_5128Kbps,
    }

    public class BlueCmd
    {
        public static string GetCmd(BlueOptions options)
        {
            string strFFCMD = string.Empty;
            switch (options)
            {
                case BlueOptions.e480x320:
                    strFFCMD = " -i {0} -c:v libx264 -s 480x320 -pix_fmt yuv420p -qp 23 -profile high444 -c:a libvo_aacenc -b:a 128k -ar 44100 -ac 2 {1}";
                    break;
                case BlueOptions.e640x480:
                    strFFCMD = " -i {0} -c:v libx264 -s 640x480 -pix_fmt yuv420p -qp 22 -profile high444 -c:a libvo_aacenc -b:a 128k -ar 44100 -ac 2 {1}";
                    break;
                case BlueOptions.e800x600:
                    strFFCMD = " -i {0} -c:v libx264 -s 800x600 -pix_fmt yuv420p -qp 21 -profile high444 -c:a libvo_aacenc -b:a 128k -ar 44100 -ac 2 {1}";
                    break;
                case BlueOptions.e1024x768:
                    strFFCMD = " -i {0} -c:v libx264 -s 1024x768 -pix_fmt yuv420p -qp 20 -profile high444 -c:a libvo_aacenc -b:a 128k -ar 44100 -ac 2 {1}";
                    break;
                case BlueOptions.e1280x720:
                    strFFCMD = " -i {0} -c:v libx264 -s 1280x720 -pix_fmt yuv420p -qp 19 -profile high444 -c:a libvo_aacenc -b:a 128k -ar 44100 -ac 2 -y {1}";
                    break;
                case BlueOptions.e1920x1080:
                    strFFCMD = " -i {0} -c:v libx264 -s 1920x1080 -pix_fmt yuv420p -qp 18 -profile high444 -c:a libvo_aacenc -b:a 128k -ar 44100 -ac 2 -y {1}";
                    break;
                case BlueOptions.Ps3720p:
                    strFFCMD = " -i {0} -c:v libx264 -s 1280x720 -pix_fmt yuv420p -qp 18 -profile high444 -c:a libvo_aacenc -b:a 128k -ar 44100 -ac 2 -y {1}";
                    break;
                case BlueOptions.ps31080p:
                    strFFCMD = " -i {0} -c:v libx264 -s 1920x1080 -pix_fmt yuv420p -qp 18 -profile high444 -c:a libvo_aacenc -b:a 128k -ar 44100 -ac 2 -y {1}";
                    break;
                case BlueOptions.TVStandardDef720x576pPALAVI:
                    strFFCMD = " -i {0} -c:v mpeg4 -s 720x576 -pix_fmt yuv420p -b:v 1500k -r 30 -c:a libvo_aacenc -b:a 128k -ar 44100 -ac 2 -y {1}";
                    break;
                case BlueOptions.TVStandardDef720x576pPALMP4:
                    strFFCMD = " -i {0} -c:v libx264 -s 720x576 -pix_fmt yuv420p -qp 19 -profile high444 -c:a libvo_aacenc -b:a 128k -ar 44100 -ac 2 -y {1}";
                    break;
                case BlueOptions.TVHighDef1280x720pPALAVI:
                    strFFCMD = " -i {0} -c:v mpeg4 -s 1280x720 -pix_fmt yuv420p -b:v 2500k -r 30 -c:a libvo_aacenc -b:a 128k -ar 44100 -ac 2 -y {1}";
                    break;
                case BlueOptions.TVHighDef1280x720pPALMP4:               

                    strFFCMD = " -i {0} -c:v libx264 -s 1280x720 -pix_fmt yuv420p -qp 18 -profile high444 -c:a libvo_aacenc -b:a 128k -ar 44100 -ac 2 -y {1}";
                    break;

                case BlueOptions.TVHighDef1920x1080pPALAVI:
                    strFFCMD = " -i {0} -c:v mpeg4 -s 1920x1080 -pix_fmt yuv420p -b:v 3000k -r 30 -c:a libvo_aacenc -b:a 128k -ar 44100 -ac 2 -y {1}";
                    break;
                case BlueOptions.TVHighDef1920x1080pPALMP4:
                    strFFCMD = " -i {0} -c:v libx264 -s 1920x1080 -pix_fmt yuv420p -qp 18 -profile high444 -c:a libvo_aacenc -b:a 128k -ar 44100 -ac 2 -y {1}";
                    break;

                case BlueOptions.TVHighDefPALMP4:
                    strFFCMD = " -i {0} -c:v libx264 -pix_fmt yuv420p -qp 18 -profile high444 -c:a libvo_aacenc -b:a 128k -ar 44100 -ac 2 -y {1}";
                    break;

                case BlueOptions.MKV1:
                    strFFCMD = " -i {0} -c:v libx264 -s 1280x720 -pix_fmt yuv420p -b:v 3000k -r 30 -profile high444 -c:a libvo_aacenc -b:a 128k -ar 44100 -ac 2 -y {1}";
                    break;
                case BlueOptions.MKV2:
                    strFFCMD = " -i {0} -c:v libx264 -s 1920x1080 -pix_fmt yuv420p -b:v 4000k -r 30 -profile high444 -c:a libvo_aacenc -b:a 128k -ar 44100 -ac 2 -y {1}";
                    break;
                case BlueOptions.SDflv:
                    strFFCMD = " -i {0} -c:v libx264 -s 480x320 -pix_fmt yuv420p -b:v 1000k -r 30 -profile high444 -c:a libvo_aacenc -b:a 128k -ar 44100 -ac 2 -y {1}";
                    break;
                case BlueOptions.Lowqualflv:
                    strFFCMD = " -i {0} -c:v libx264 -s 320x240 -pix_fmt yuv420p -b:v 800k -r 30 -profile high444 -c:a libvo_aacenc -b:a 96k -ar 44100 -ac 2 -y {1}";
                    break;
                case BlueOptions.Mediumqualflv:
                    strFFCMD = " -i {0} -c:v libx264 -s 480x320 -pix_fmt yuv420p -b:v 1000k -r 30 -profile high444 -c:a libvo_aacenc -b:a 128k -ar 44100 -ac 2 -y {1}";
                    break;
                case BlueOptions.Highqualflv:
                    strFFCMD = " -i {0} -c:v libx264 -s 720x576 -pix_fmt yuv420p -b:v 1500k -r 30 -profile high444 -c:a libvo_aacenc -b:a 192k -ar 44100 -ac 2 -y {1}";
                    break;
                case BlueOptions.flv:
                    strFFCMD = " -i {0} -c:v libx264 -pix_fmt yuv420p -b:v 1500k -r 30 -profile high444 -c:a libvo_aacenc -b:a 192k -ar 44100 -ac 2 -y {1}";
                    break;
                case BlueOptions.Mp3_320kbs:
                    strFFCMD = " -i {0} -vn -c:a libmp3lame -b:a 320k -ar 44100 -ac 2 -y {1}";
                    break;
                case BlueOptions.Mp3_192kbs:
                    strFFCMD = " -i {0} -vn -c:a libmp3lame -b:a 192k -ar 44100 -ac 2 -y {1}";
                    break;
                case BlueOptions.Mp3_128kbs:
                    strFFCMD = " -i {0} -vn -c:a libmp3lame -b:a 128k -ar 44100 -ac 2 -y {1}";
                    break;
                case BlueOptions.LosslessCopy:
                    strFFCMD = " -i {0} -c:v libx264 -qp 0 -c:a libvo_aacenc -b:a 320k -ar 44100 -ac 2 -y {1}";
                    break;


                case BlueOptions.M3U8_416X234_264Kbps:
                    //帧率：          12
                    //尺寸：          416 x 234
                    //码流：          264Kbps
                    //视频：          200Kbps
                    //音频：          56Kbps
                    //音频采样：   48KHz
                    //MP4 描述：  baseling3.0
                    //时长：          10s

                    //命令如下：
                    //$ ffmpeg -i The.Interview.2014.BluRay.720p.x264.AAC-PHD.mp4   \
                    //-c:v libx264  \
                    //-r 12      \ 
                    //-s 416X234       \
                    //-b:v 200k       \
                    //-profile:v baseline      \
                    //-b:a 56k      \
                    //-hls_time 10      \
                    //-hls_list_size 0      \
                    //-hls_allow_cache 1      \
                    //-hls_base_url http://127.0.0.1:8080/videos/264k/       \
                    //-hls_segment_filename /Users/kuoxin/Movies/264k/'TI2014_264k_%05d.ts’       \
                    //Users/kuoxin/Movies/264K/264k_mp4.m3u8 
                    //strFFCMD = @"-i  {0} -c:v libx264 -r 15 -s 480X270 -b:v 400k -b:a 56k -c:a aac -strict -2 -f hls -hls_time 10 -hls_list_size 0 -hls_allow_cache 1 -hls_base_url {2}  -hls_wrap 0 {1}";
                    strFFCMD = @"-i  {0} -c:v libx264 -r 12 -s {3}x{4} -b:v 288k -profile:v baseline -b:a 56k -c:a aac -strict -2 -f hls -hls_time 10 -hls_list_size 0 -hls_allow_cache 1 -hls_base_url {2}  -hls_wrap 0 {1}";
                    //strFFCMD = @"-i  {0} -c:v libx264 -r 12 -s 480x270 -b:v 400k -profile:v baseline -b:a 56k -c:a aac -strict -2 -f hls -hls_time 10 -hls_list_size 0 -hls_allow_cache 1 -hls_base_url {2}  -hls_wrap 0 {1}";

                    break;
                case BlueOptions.M3U8_480X270_464Kbps:
                    //移动网络464Kbps视频编码
                    //帧率：          15
                    //尺寸：          480 x 270
                    //码流：          464Kbps
                    //视频：          400Kbps
                    //音频：          56Kbps
                    //音频采样：   48KHz
                    //MP4 描述：  baseline
                    //时长：          10s
                    //$ ffmpeg -i The.Interview.2014.BluRay.720p.x264.AAC-PHD.mp4        \
                    //-c:v libx264      \
                    //-r 15       \
                    //-s 480X270       \
                    //-b:v 400k       \
                    //-profile:v baseline      \
                    //-b:a 56k      \
                    //-hls_time 10      \
                    //-hls_list_size 0      \
                    //-hls_allow_cache 1      \
                    //-hls_base_url http://127.0.0.1:8080/videos/464k/       \
                    //-hls_segment_filename /Users/kuoxin/Movies/464k/'TI2014_464k_%05d.ts’      \
                    ///Users/kuoxin/Movies/464K/464k_mp4.m3u8 

                    //移动网络464Kbps视频编码
                    //分成TS片段
                    //-i  C:\temp\22.mp4 -c:v libx264 -c:a aac -strict -2 -f hls -hls_time 10 -hls_list_size 0 -hls_wrap 0 c:\temp\output.m3u8
                    strFFCMD = @"-i  {0} -c:v libx264 -r 15 -s {3}x{4} -b:v 576k -profile:v baseline -b:a 56k -c:a aac -strict -2 -f hls -hls_time 10 -hls_list_size 0 -hls_allow_cache 1 -hls_base_url {2}  -hls_wrap 0 {1}";
                   // strFFCMD = @"-i  {0} -c:v libx264 -r 15 -s 480X360 -b:v 576k -profile:v baseline -b:a 56k -c:a aac -strict -2 -f hls -hls_time 10 -hls_list_size 0 -hls_allow_cache 1 -hls_base_url {2}  -hls_wrap 0 {1}";

                    break;



                case BlueOptions.M3U8_640X360_664Kbps:
                    //WiFi/CELL 664Kbps视频编码
                    //帧率：          视频当前帧数
                    //尺寸：          640 x 360
                    //码流：          664Kbps
                    //视频：          600Kbps
                    //音频：          56Kbps
                    //音频采样：   48KHz
                    //MP4 描述：  baseline
                    //时长：          10s
                    //$ ffmpeg -i The.Interview.2014.BluRay.720p.x264.AAC-PHD.mp4        \
                    //-c:v libx264      \
                    //-s 640X360       \
                    //-b:v 400k       \
                    //-profile:v baseline      \
                    //-b:a 56k      \
                    //-hls_time 10      \
                    //-hls_list_size 0      \
                    //-hls_allow_cache 1      \
                    //-hls_base_url http://127.0.0.1:8080/videos/664k/       \
                    //-hls_segment_filename /Users/kuoxin/Movies/664k/'TI2014_464k_%05d.ts’      \
                    ///Users/kuoxin/Movies/664K/664k_mp4.m3u8 
                    strFFCMD = @"-i  {0} -c:v libx264  -s {3}x{4} -b:v 864k -profile:v baseline -b:a 56k -c:a aac -strict -2 -f hls -hls_time 10 -hls_list_size 0 -hls_allow_cache 1 -hls_base_url {2}  -hls_wrap 0 {1}";
                    //strFFCMD = @"-i  {0} -c:v libx264 -s 640x480 -b:v 864k -profile:v baseline -b:a 56k -c:a aac -strict -2 -f hls -hls_time 10 -hls_list_size 0 -hls_allow_cache 1 -hls_base_url {2}  -hls_wrap 0 {1}";

                    break;
                case BlueOptions.M3U8_640X360_1294Kbps:
                    //WiFi 1294Kbps视频编码
                    //帧率：          视频当前帧数
                    //尺寸：          640 x 360
                    //码流：          1296Kbps
                    //视频：          1200Kbps
                    //音频：          96Kbps
                    //音频采样：   48KHz
                    //MP4 描述：  baseline
                    //时长：          10s
                    //$ ffmpeg -i The.Interview.2014.BluRay.720p.x264.AAC-PHD.mp4        \
                    //-c:v libx264      \
                    //-s 640X360       \
                    //-b:v 1200k       \
                    //-profile:v baseline      \
                    //-b:a 96k      \
                    //-hls_time 10      \
                    //-hls_list_size 0      \
                    //-hls_allow_cache 1      \
                    //-hls_base_url http://127.0.0.1:8080/videos/1296k/       \
                    //-hls_segment_filename /Users/kuoxin/Movies/1296k/'TI2014_1296k_%05d.ts’      \
                    ///Users/kuoxin/Movies/1296K/1296k_mp4.m3u8 
                    strFFCMD = @"-i  {0} -c:v libx264 -b:v 1800k -profile:v baseline -b:a 96k -c:a aac -strict -2 -f hls -hls_time 10 -hls_list_size 0 -hls_allow_cache 1 -hls_base_url {2}  -hls_wrap 0 {1}";
                    //strFFCMD = @"-i  {0} -c:v libx264 -s {3}x{4} -b:v 200k -profile:v baseline -b:a 96k -c:a aac -strict -2 -f hls -hls_time 10 -hls_list_size 0 -hls_allow_cache 1 -hls_base_url {2}  -hls_wrap 0 {1}";

                    //  strFFCMD = @"-i  {0} -c:v libx264 -s 1280x720 -b:v 1800k -profile:v baseline -b:a 96k -c:a aac -strict -2 -f hls -hls_time 10 -hls_list_size 0 -hls_allow_cache 1 -hls_base_url {2}  -hls_wrap 0 {1}";


                    break;

                case BlueOptions.M3U8_960X540_3596Kbps:
                    //WiFi 3596Kbps视频编码
                    //帧率：          视频当前帧数
                    //尺寸：          960 x 540
                    //码流：          3596Kbps (当前最高码流只有：1780Kbps)
                    //视频：          3500Kbps(当前最高码流只有：1648Kbps)
                    //音频：          96Kbps
                    //音频采样：   48KHz
                    //MP4 描述：  main
                    //时长：          10s
                    //$ ffmpeg -i The.Interview.2014.BluRay.720p.x264.AAC-PHD.mp4        \
                    //-c:v libx264      \
                    //-s 960X540       \
                    //-b:a 128k          \
                    //-hls_time 10      \
                    //-hls_list_size 0      \
                    //-hls_allow_cache 1      \
                    //-hls_base_url http://127.0.0.1:8080/videos/3596k/       \
                    //-hls_segment_filename /Users/kuoxin/Movies/3596k/'TI2014_3596k_%05d.ts’      \
                    ///Users/kuoxin/Movies/3596K/3596k_mp4.m3u8 
                    ///
                    strFFCMD = @"-i  {0} -c:v libx264 -s 960X540  -b:a 128k -c:a aac -strict -2 -f hls -hls_time 10 -hls_list_size 0 -hls_allow_cache 1 -hls_base_url {2}  -hls_wrap 0 {1}";

                    break;
                case BlueOptions.M3U8_1280X720_5128Kbps:
                    //WiFi 5128Kbps视频编码
                    //帧率：          视频当前帧数
                    //尺寸：          1280 x 720
                    //码流：          5128k (当前最高码流只有：1780Kbps)
                    //视频：          5000Kbps(当前最高码流只有：1648Kbps)
                    //音频：          128Kbps
                    //音频采样：   48KHz
                    //MP4 描述：  main
                    //时长：          10s

                    //$ ffmpeg -i The.Interview.2014.BluRay.720p.x264.AAC-PHD.mp4        \
                    //-c:v libx264      \
                    //-b:a 128k          \
                    //-hls_time 10      \
                    //-hls_list_size 0      \
                    //-hls_allow_cache 1      \
                    //-hls_base_url http://127.0.0.1:8080/videos/5128k/       \
                    //-hls_segment_filename /Users/fengkun/Movies/kuoxin/'TI2014_5128k_%05d.ts’      \
                    ///Users/kuoxin/Movies/5128K/5128k_mp4.m3u8 
                    strFFCMD = @"-i  {0} -c:v libx264 -s 1280X720 -b:a 128k -c:a aac -strict -2 -f hls -hls_time 10 -hls_list_size 0 -hls_allow_cache 1 -hls_base_url {2}  -hls_wrap 0 {1}";
                    break;
                //WiFi 1294Kbps视频编码
                default:
                    break;
            }
            return strFFCMD;
        }
    }
    //public class BlueCmd
    //{
    //    //{0} input {1} output
    //    public static string Cmd480x320 = 
    //}
}
